package org.jeecg.modules.demo.mall.util;

import java.text.DecimalFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Random;

/**
 * @author xingwei@yuanmashidai.com
 * @describe
 * @date 2023-01-31 14:15
 **/
public class NoUtil {

    public static final String ORDER_NO = "OR";

    public static String getOrderNo() {
        return generateNo(ORDER_NO, true);
    }
    public static String randPwd() {
        StringBuilder sb = new StringBuilder();
        Integer randomInt = (new Random()).nextInt(999999);
        String random = (new DecimalFormat("000000")).format(randomInt);
        sb.append(random);
        return sb.toString();
    }

    private static String generateNo(String typeCode, boolean isShort) {
        StringBuilder sb = new StringBuilder();
        sb.append(typeCode);
        if (isShort) {
            sb.append(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyMMddHHmmss")));
        } else {
            sb.append(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyMMddHHmmssSSS")));
        }
        Integer randomInt = (new Random()).nextInt(9999);
        String random = (new DecimalFormat("0000")).format(randomInt);
        sb.append(random);
        return sb.toString();
    }


}
